package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.service.ReportService;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {

    @Autowired
    private MemberDao memberDao;

    @Autowired
    private OrderDao orderDao;


    @Override
    public Map<String, Object> getBusinessData()throws Exception {
        //获取当前日期
        Date now = DateUtils.getToday();
        //获取本周第一天的日期
        Date firstDayOfWeek = DateUtils.getFirstDayOfWeek(now);
        //获取本月第一天的日期
        Date firstDay4ThisMonth = DateUtils.getFirstDay4ThisMonth();

        //获取当日新增会员数
        int todayNewMember= memberDao.getMemberCountByDate(now);
        //获取总会员数
        int totalMember = memberDao.getTotalMemberCount();
        //获取本周新增会员数
        int thisWeekNewMember = memberDao.getMemberCountAfterDate(firstDayOfWeek);
        //获取本月新增会员数
        int thisMonthNewMember = memberDao.getMemberCountAfterDate(firstDay4ThisMonth);
        //获取今日新增预约
        int todayOrderNumber = orderDao.getOrderCountByDate(now);
        //获取今日到诊数
        int todayVisitsNumber = orderDao.getVisitsCountByDate(now);
        //获取本周新增预约数
        int thisWeekOrderNumber = orderDao.getOrderCountAfterDate(firstDayOfWeek);
        //获取本周到诊数
        int thisWeekVisitsNumber = orderDao.getVisitsCountAfterDate(firstDayOfWeek);
        //获取本月新增预约数
        int thisMonthOrderNumber = orderDao.getOrderCountAfterDate(firstDay4ThisMonth);
        //获取本月到诊数
        int thisMonthVisitsNumber = orderDao.getVisitsCountAfterDate(firstDay4ThisMonth);

        //获取热门套餐数据
        List<Map> hotSetmeal= orderDao.hotSetmeal();


        Map<String,Object> map = new HashMap();
        map.put("reportDate",DateUtils.parseDate2String(now));
        map.put("todayNewMember",todayNewMember);
        map.put("totalMember",totalMember);
        map.put("thisWeekNewMember",thisWeekNewMember);
        map.put("thisMonthNewMember",thisMonthNewMember);
        map.put("todayOrderNumber",todayOrderNumber);
        map.put("todayVisitsNumber",todayVisitsNumber);
        map.put("thisWeekOrderNumber",thisWeekOrderNumber);
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        map.put("thisMonthOrderNumber",thisMonthOrderNumber);
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        map.put("hotSetmeal",hotSetmeal);


        return map;
    }
}
